<template>
	<view class="main">
		<u-swiper :list="list1" :height="140">

		</u-swiper>

		<view class="message" v-if="text1">
			<u-notice-bar @click="toNotice" :text="text1" color="#666666" bgColor="#fff" mode="link"></u-notice-bar>
		</view>

		<!-- tabs -satrt -->
		<view class="tabs">
			<view class="tabs-item" :class="[queryParams.flag ==1?'tabs-item-active':'']" @click="switchTabs(1)">
				<span class="tabs-item-text">采购信息</span>
			</view>
			<view class="tabs-line"></view>
			<view class="tabs-item" :class="[queryParams.flag ==2?'tabs-item-active':'']" @click="switchTabs(2)">
				<span class="tabs-item-text">销售信息</span>
			</view>
		</view>
		<!-- tabs -end -->

		<!--list-satrt -->
		<view class="list">
			<view class="item" v-for="item in dataList" @click="toDetail(item.id)">
				<image :src="item.cover" class="item-img"></image>
				<view class="item-content">
					<view class="item-name">{{item.name}}</view>
					<view class="item-tag">{{item.category}}</view>
					<view class="item-price"><span class="item-price-unit">¥</span>{{item.unitPrice}}</view>
				</view>
			</view>
		</view>
		<!--list-end -->


		<view class="list-end" v-if="dataList.length">{{endText}}</view>

		<u-empty v-if="!dataList.length" mode="car" text="暂无数据" icon="/static/empty-img.png">
		</u-empty>



	</view>
</template>

<script>
	import db from '@/common/localstorage.js'
	export default {
		data() {
			return {
				// list1: [
				// 	'https://cdn.uviewui.com/uview/swiper/swiper1.png',
				// 	'https://cdn.uviewui.com/uview/swiper/swiper2.png',
				// 	'https://cdn.uviewui.com/uview/swiper/swiper3.png',
				// ],
				list1: [],
				
				msgId:'',
				text1: '',
				userInfo: {},
				queryParams: {
					flag: 1,
					pageNum: 1,
					pageSize: 10
				},
				total: 0,
				endText: '',
				dataList: []

			}
		},
		onLoad() {
			this.userInfo = db.get('userInfo')
			this.getMessage()
			this.getImgs()
		},
		onShow() {
			this.queryParams.pageNum = 1
			this.dataList = []
			this.getList()

		},
		methods: {
			getMessage() {
				let that = this
				this.$postjson('/api/RqNotice/list', {
					"pageNum": 1,
					"pageSize": 5
				}).then(res => {
					let data = res.data.rows?res.data.rows:[]
					if(data.length){
						this.text1 = data[0].name
						this.msgId = data[0].id
					}
				})
			},
			getImgs() {
				let that = this
				this.$postjson('/api/RqHome/list', {}).then(res => {
					let data = res.data.data
					this.list1 = data.map(o => {
						return that.baseUrl + o.images
					})
				})
			},
			getList() {
				this.$modal.msgLoading('加载中')

				var that = this
				let url = this.queryParams.flag == 1 ? '/api/PurchaseInfo/list' :
					'/api/RqSaleInfo/list'
				this.$postjson(url, this.queryParams).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						let detail = res.data.rows
						
						detail.forEach(v=>{
							let img =v.images? v.images.split(','):[]
							if(img.length){
								v.cover = that.baseUrl + img[0]
							}
						})

						if (detail.length < that.queryParams.pageSize) {
							that.endText = '没有更多了'
						}
						
						
						that.total = res.data.total
						that.dataList = that.dataList.concat(detail)
						
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
					}
				})
			},

			switchTabs(flag) {
				this.queryParams.flag = flag
				this.queryParams.pageNum = 1
				this.dataList = []
				this.getList()
			},

			toDetail(id) {
				uni.navigateTo({
					url: '/pages/index/goodsInfo?id='+id+'&flag='+this.queryParams.flag
				})
			},
			toNotice() {
				uni.navigateTo({
					url: '/pages/notice/index?id='+this.msgId
				})
			}

		},

		onReachBottom: function(e) {
			if (this.total > this.dataList.length) {
				(this.queryParams.pageNum) ++;
				this.getList()
			}
		},
	}
</script>

<style lang="scss" scoped>
	.message {
		margin-top: 20upx;

		::v-deep .u-notice-bar {
			border-radius: 4upx;
		}

		::v-deep .uicon-arrow-right {
			color: #999 !important;
			font-size: 28upx !important;
		}

		::v-deep .u-notice__left-icon {
			align-items: flex-start;
			flex-direction: row;
			width: 110upx;
			position: relative;

			.uicon-volume {
				color: #F01022 !important;
			}
		}

		::v-deep .u-notice__left-icon::after {
			content: '公告';
			padding-left: 10upx;
			font-family: AlimamaShuHeiTi, AlimamaShuHeiTi;
			font-weight: bold;
			font-size: 28upx;
			color: #F01022;
		}
	}

	page {
		background: #F9F9F9;
	}

	.main {
		padding: 24upx;
		padding-bottom: 260upx;
	}

	.list {
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;

		.item {
			margin-bottom: 20upx;
			width: calc(50% - 12upx);
			background: #FFFFFF;
			border-radius: 10upx;
			height: 460upx;

			.item-img {
				width: 100%;
				height: 236rpx;
				overflow: hidden;
				margin-bottom: 20upx;
				background: #999999;
				border-radius: 10upx 10upx 0 0;
			}

			.item-content {
				height: calc(100% - 236upx);
				padding: 0 20upx;
				position: relative;
			}

			.item-name {
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28upx;
				color: #111111;
				line-height: 36upx;
				margin-bottom: 10upx;
				-webkit-box-orient: vertical;
				display: -webkit-box;
				overflow-wrap: break-word; //强制换行
				overflow: hidden;
				text-overflow: ellipsis;
				-webkit-line-clamp: 2; //超出多少行数显示省略号
			}

			.item-tag {
				width: 96upx;
				height: 32upx;
				background: #FFFFFF;
				border-radius: 4upx;
				border: 2upx solid #12C66B;
				text-align: center;
				line-height: 32upx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 20rpx;
				color: #12C66B;
			}

			.item-price {
				position: absolute;
				bottom: 45upx;
				font-family: Roboto, Roboto;
				font-weight: 500;
				font-size: 40rpx;
				color: #F01022;

				.item-price-unit {
					font-family: DINAlternate, DINAlternate;
					font-weight: bold;
					font-size: 24rpx;
					color: #F01022;
				}
			}
		}

	}

	.tabs {
		// margin-top: 26upx;
		width: 100%;
		height: 106upx;
		display: flex;
		align-items: center;
		z-index: 3;
		position: relative;

		.tabs-item {
			height: 106upx;
			line-height: 106upx;
			text-align: center;
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 30upx;
			color: #999999;
			width: 50%;

		}

		.tabs-item-active {
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 32upx;
			color: #111111 !important;
			position: relative;
			z-index: 4;
		}

		.tabs-item-text {
			position: relative;
			z-index: 4;
		}

		.tabs-item-active::after {
			content: '';
			position: absolute;
			width: 152upx;
			height: 10upx;
			background: #12C66B;
			bottom: 34upx;
			left: 50%;
			transform: translateX(-50%);
			z-index: 0;
		}

		.tabs-line {
			width: 2upx;
			height: 40upx;
			background: rgba(228, 228, 228, 1);
		}
	}
</style>